package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	var wg sync.WaitGroup
	fmt.Println("main start")
	count := 6
	wg.Add(count)
	// fmt.Println(runtime.NumGoroutine())

	go func() {
		fmt.Println("父协程开始，准备启动子协程")
		defer func() {
			wg.Done()
			fmt.Println("父协程结束了~~~~~")
		}()
		for i := 0; i < count-1; i++ {
			go func(id int) {
				defer wg.Done()
				fmt.Printf("子协程 %d 运行中\n", id)
				time.Sleep(5 * time.Second)
				fmt.Printf("子协程 %d 结束\n", id)
			}(i)
		}
	}()

	wg.Wait()
	fmt.Println("main end")
}
